pick-file-from-system

  1. MediaStore.Video.Media.EXTERNAL_CONTENT_URI Uri
  2. MediaStore.Video.Media.DATA String
  3. MediaStore.Video.Media.DURATION String
    1
    2
    3
    4
    5
    6
    private void startSelectVideoActivity() {
    Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
    i.setType("video/*");
    startActivityForResult(i, REQUEST_CODE_SELECT_VIDEO);
    overridePendingTransition(R.anim.slide_in_from_bottom, R.anim.slide_out_to_bottom);
    }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_SELECT_VIDEO && resultCode == RESULT_OK && null != data) {
Uri selectedVideo = data.getData();
String videoPath = null;

if (selectedVideo.getScheme().equalsIgnoreCase("file")) {
videoPath = selectedVideo.getPath();
} else {
String[] filePathColumn = {MediaStore.Video.Media.DATA, MediaStore.Video.Media.DURATION};
Cursor cursor = getContentResolver().query(selectedVideo,
filePathColumn, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
videoPath = cursor.getString(columnIndex);
//duration = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION));
cursor.close();
}
}